extends Area2D

@export var slime_speed:float = 50
@export var  animator:AnimatedSprite2D;
var dead:bool = false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	if not dead:
		position.x+=delta*-slime_speed
	if position.x <= -250:
		get_tree().current_scene.getawaySlimeNum+=1
		queue_free()

func _on_body_entered(body: Node2D) -> void:
	if body is CharacterBody2D and not body.isDead:
		body.hurt()


func _on_area_entered(area: Area2D) -> void:
	if area.is_in_group("Bullet") and not dead:
		dead = true
		$AudioStreamPlayer.play()
		get_tree().current_scene.score+=1
		get_tree().current_scene.noStopKillNum+=1
		print(get_tree().current_scene.score)
		animator.play("die")
		await get_tree().create_timer(0.88).timeout
		queue_free()
